class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class LinkList:
    def __init__(self):
        self.head = ListNode(-1)
        pass

    def addNode(self, x):
        newNode = ListNode(x)
        tmpNode = self.head
        while tmpNode.next != None:
            tmpNode = tmpNode.next
        tmpNode.next = newNode

    def print_list(self):
        tmpNode = self.head.next
        while tmpNode != None:
            if tmpNode.val != -1:
                print(tmpNode.val)
            tmpNode = tmpNode.next



class Solution:
    def addTwoNumbers(self, l1, l2):
        result_list = LinkList()

        tmp1 = l1.head.next
        tmp2 = l2.head.next
        low_num = 0
        while tmp1 != None and tmp2 != None:
            val = tmp1.val + tmp2.val + low_num
            if val < 10:
                result_list.addNode(val)
                low_num = 0
            else:
                result_list.addNode(val - 10)
                low_num = 1

            tmp1 = tmp1.next
            tmp2 = tmp2.next

        if low_num != 0:
            result_list.addNode(low_num)

        return  result_list
        pass


if __name__ == '__main__':
    ll1 = LinkList()
    for x in [9]:
        ll1.addNode(x)

    ll2 = LinkList()
    for x in [9]:
        ll2.addNode(x)

    sl = Solution()
    lr = sl.addTwoNumbers(ll1, ll2)
    lr.print_list()
